package com.example.tests;

import java.util.Set;
import java.util.logging.Logger;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.example.fw.GroupObject;

public class GroupCreationTests extends TestBase {
	
	private Logger log = Logger.getLogger("GroupCreationTests");
	
	@Test(dataProvider = "groupsFromFile", dataProviderClass = GroupDataGenerator.class)
	public void testValidGroupCanBeCreated(GroupObject validGroup) throws Exception {
		Set<GroupObject> oldList = app.getHibernateHelper().getGroups();
		log.info("oldList =" + oldList);
		app.getGroupHelper().createGroup(validGroup);
		log.info("validGroup =" + validGroup);
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		log.info("newList =" + newList);
		verifyGroupAdded(oldList, validGroup, newList);
		log.info("testValidGroupCanBeCreated end");
}
	
	@Test
	public void testUiConformsWithDb(GroupObject validGroup) throws Exception {
		Set<GroupObject> dbList = app.getHibernateHelper().getGroups();
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		Assert.assertEquals(newList, dbList);
	
}
	
	@Test
	public void testGroupWithEmptyDataCanBeCreated() throws Exception {
		GroupObject emptyDataGroup = new GroupObject()
			.setName("")
			.setHeader("")
			.setFooter("");
		Set<GroupObject> oldList = app.getGroupHelper().getGroups();
		app.getGroupHelper().createGroup(emptyDataGroup);
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		verifyGroupAdded(oldList, emptyDataGroup, newList);
	}
	
}